package thread;


public class work_demo9 {


    public static void main(String[] args) {
        int[] arr = {1,1,1,1,1,6};
        int x = getPos(arr,6,1);
        System.out.println(x);
    }
    public static int getPos(int[] A, int n, int val) {
        // write code here
        int left = 0;
        int right = n - 1;
        while(left <= right){
            int mid = (left +right)/2;
            if(A[mid] == val && (mid == 0 || A[mid]!=A[mid-1])){
                return mid ;
            }else if(A[mid]<val){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return -1;
    }
}
